<?php
session_start();
/*
 * Session variables:
 * $_SESSION['type'] [string] = user type of the logged in user
 * $_SESSION['authorised'] [boolean] = whether or not the current user is logged in
 */
if(isset($_SESSION['authorised']) && $_SESSION['authorised'] == true)
{   
    if(isset($_SESSION['type']))
    {
        if($_SESSION['type'] == 'administrator')
        {
			
			$username= $_SESSION['account_name'];
			$contact_person=strtoupper(addslashes(pg_escape_string($_POST['contact_person'])));
			$contact_number=addslashes(pg_escape_string($_POST['contact_number']));
			$educ_attainment=strtoupper(addslashes(pg_escape_string($_POST['educ_attainment'])));
            
			include('connection.inc');
				
			$sql="INSERT INTO teachers (username, emergency_contact_person, emergency_contact_number, educational_attainment) VALUES ('$username', '$contact_person', '$contact_number' , '$educ_attainment')";
			$result=pg_query($sql);
				
			header('Location: admin_emailcreateaccount.php');
			exit();
        }
        elseif($_SESSION['type'] == 'student')
        {
            header('Location: student_index.php');
            exit();
        }
        elseif($_SESSION['type'] == 'tutor')
        {
            header('Location: tutor_index.php');
            exit();
        }
        elseif($_SESSION['type'] == 'parent')
        {
            header('Location: parent_index.php');
            exit();
        }
    }
}
else
{
    header('Location: index.php');
}
?>
